const path = require('path');
const webpack = require("webpack");
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

// 转发接口
const proxyIp = 'http://localhost:8080';


module.exports = {
    // 输出目录
    assetsDir: 'static',//打静态资源都打包到static的这个文件夹下
    //publicPath: '/v2_demo',//在静态资源前面增加前缀,主要用于ng路径
    pages: {
        index: {
             entry: 'src/main.js',
             template: 'public/index.html',
             filename: 'index.html',
        },
    },
    productionSourceMap:false,//打包后不生成.map文件
    devServer: {// 环境配置
        host: 'localhost',
        port: 8080,
        https: false,
        hotOnly: false,
        open: true, //配置自动启动浏览器
        proxy: {// 配置多个代理(配置一个 proxy: 'http://localhost:4000' )
            '/api': {
                target: proxyIp,
            },
            '/user': {
                target: proxyIp
            },
            '/good': {
                target: proxyIp
            },
            '/order': {
                target: proxyIp
            }
        }
    },
    //其他配置....
    configureWebpack: config => {
        return {
            // 使用cdn
            externals: {
                vue: "Vue",
                vuex: "Vuex",
                axios: 'axios',
                "vue-router": "VueRouter",
            },
            plugins: [
                //开启gzip压缩
                new CompressionWebpackPlugin({
                    test:/\.js$|\.html$|.\css/, //匹配文件名
                    threshold: 10240,//对超过10k的数据压缩
                    deleteOriginalAssets: false //不删除源文件
                }),
                //使用包分析工具
                new BundleAnalyzerPlugin(),
            ],
        }
    },
};